﻿#ifndef TCPSERVER_H
#define TCPSERVER_H

#include <QtNetwork>
#include <QDebug>

class CTcpServer : public QTcpServer
{
    Q_OBJECT
public:
    explicit CTcpServer(QObject *parent = 0);

private:
    QList<QTcpSocket *> m_clients;

protected:
	void incomingConnection(qintptr handle);

private slots:
    void slot_disconnected();

signals:
    void sig_receiveData(QByteArray revData,QString ip,quint16 port);

    // 客户端上线提示
    void sig_clientConnected(const QString &ip, int port);

    // 客户端下线的提示
    void sig_clientDisconnected(const QString &ip, int port);

    void sig_readyRead(QString ip,quint16 port);

public slots:
    /*启动服务
     * @param:  servPort 服务器端口号
    */
    bool slot_start(quint16 servPort);
    //停止服务
    void slot_stop();

    //指定连接发送数据
	void slot_writeData(const QString &ip,
                        int port,
                        const char *pch,
						qint64 maxSize);
    //对所有连接发送数据
    void slot_writeData(const char *pch, qint64 maxSize);

    void slot_receiveData();

    void slot_ReadData(const QString &ip,
                       int port,
                       char *pch,
                       qint64 maxSize);

};

#endif // TCPSERVER_H
